var dataSource = new Array();
//table的数据源
var table; //table对象
dataSource = [];

function getAllWare(){ //获取所有的发货仓
    var sel = document.getElementById("dcName");
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/abaseservice/area/getAllWarehouse',
        cache: false, //禁用缓存
        type: "POST",
        dataType:"json",
        data:{},
        success: function(obj){
            for(var i=0;i<obj.data.length;i++){
                var option = new Option(obj.data[i].warehouse_name,obj.data[i].warehouse_code);
                sel.options.add(option)
            }

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            //console.log(XMLHttpRequest);
            alert(XMLHttpRequest);
        }
    });
}



$("#wayCancel").click(function () {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
})

function waySave() {

    var loginData=JSON.parse(web.readCookie("loginData"));
    var  warehouseCode = $('#dcName option:selected').val();
    var warehouseName = $('#dcName option:selected').text();
    var transportType = $('#type option:selected').val();
    var transportModeType = $('#typeWay option:selected').val();
    var edgeLimit= $("input:radio[name='maxLong']:checked").val();
    var maximumEdgeLimit = $("#longLimit").val();
    var weightLimit = $("input:radio[name='maxWeight']:checked").val();
    var minWeightLimit = $("#wightLimit1").val();
    var maxWeightLimit = $("#wightLimit2").val();
    var volumeLimit = $("input:radio[name='maxVolume']:checked").val();
    var volumeWeight = $("#volumeLimit").val();
    var transportStatus = $("input:radio[name='status']:checked").val();
    var createUser  = loginData.user.name;
    var datas = {
            warehouseCode: warehouseCode,
            warehouseName: warehouseName,
            transportType: transportType,
            transportModeType: transportModeType,
            edgeLimit: edgeLimit,
            maximumEdgeLimit: maximumEdgeLimit,
            weightLimit: weightLimit,
            minWeightLimit: minWeightLimit,
            maxWeightLimit: maxWeightLimit,
            volumeLimit: volumeLimit,
            volumeWeight: volumeWeight,
            transportStatus: transportStatus,
            createUser: createUser
            }

    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/alogistics/addDispatchMode.jhtml',
        cache: false, //禁用缓存
        type: "POST",
        dataType:'json',
        data: datas,
        success: function(result){
            if(result.sub_code == 0){
                layer.msg(result.sub_msg, {
                    icon: 1,
                    time: 1000,
                    end: function () {
                        var index =  parent.location.reload();
                        parent.layer.close(index);
                    }
                });
            }else{
                layer.msg(result.sub_msg, {icon: 5,time:2000});
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            //alert(XMLHttpRequest);
        }
    });
}


$("[name='maxLong']").change(function () { //长度为无限制的时候无法输入
    if(this.value == 20){
         $("#longLimit").attr("disabled","disabled");
         $("#longLimit").val("")
    }else{
        $("#longLimit").attr("disabled",false);
    }
})


$("[name='maxWeight']").change(function () { //重量为无限制的时候无法输入
    if(this.value == 20){
        $("#wightLimit1").val("");
        $("#wightLimit2").val("");
        $("#wightLimit1").attr("disabled","disabled");
        $("#wightLimit2").attr("disabled","disabled");
    }else{
        $("#wightLimit1").attr("disabled",false);
        $("#wightLimit2").attr("disabled",false);
    }
})

$("[name='maxVolume']").change(function () { //体积为无限制的时候无法输入
    if(this.value == 20){
        $("#volumeLimit").val("")
        $("#volumeLimit").attr("disabled","disabled");
    }else{
        $("#volumeLimit").attr("disabled",false);
    }
})


$("#type").change(function () {
    if($('#type option:selected').val() == 10){
        var typeWay = document.getElementById("typeWay");
        $(typeWay).html("");
        var option4 = new Option("鑫方盛物流","40");
        typeWay.options.add(option4);
    }

    if($('#type option:selected').val() == 20){
        var typeWay = document.getElementById("typeWay");
        $(typeWay).html("");
        var option = new Option("快递","10");
        var option1 = new Option("快运","20");
        var option2= new Option("专车包车","30");
        typeWay.options.add(option);
        typeWay.options.add(option1);
        typeWay.options.add(option2);
    }
})



$("#typeWay").change(function () {
    if($('#typeWay option:selected').val() == 30){
        $("input[type='radio'][name='maxLong']").get(0).checked = true;
        $("input[type='radio'][name='maxWeight']").get(0).checked = true;
        $("input[type='radio'][name='maxVolume']").get(0).checked = true;
        $("#longLimit").attr("disabled","disabled");
        $("#wightLimit1").attr("disabled","disabled");
        $("#wightLimit2").attr("disabled","disabled");
        $("#volumeLimit").attr("disabled","disabled");

        $($("input[type='radio'][name='maxLong']").get(1)).attr("disabled", true);
        $($("input[type='radio'][name='maxWeight']").get(1)).attr("disabled", true);
        $($("input[type='radio'][name='maxVolume']").get(1)).attr("disabled", true);
    }
})



